package com.css.fxfzcpxx.modules.infoRetrieval.historicalSeismicInfo.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzcpxx.base.log.Log;
import com.css.fxfzcpxx.base.response.RestResponse;
import com.css.fxfzcpxx.modules.infoRetrieval.historicalSeismicInfo.param.EarthquakeDisasterInfoParam;
import com.css.fxfzcpxx.modules.infoRetrieval.historicalSeismicInfo.service.EarthquakeDisasterInfoService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Author: zhangSongRui
 * @CreateTime: 2023/04/08
 * @Description: 地震灾害信息
 */
@Api(tags ="地震灾害信息")
@Slf4j
@RestController
@RequestMapping("/earthquakeDisasterInfo")
public class EarthquakeDisasterInfoController {
    @Resource
    private EarthquakeDisasterInfoService earthquakeDisasterInfoService;

    /**
     * 分页列表
     * @param param 参数
     * @return page
     */
    @GetMapping("/getPage")
    @Log(value="信息检索",type = "检索")
    public RestResponse getPage(HttpServletRequest request, EarthquakeDisasterInfoParam param) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            int curPage =1 ;//Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = 10;//Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            Map<String, Object> page = earthquakeDisasterInfoService.getPage(curPage, pageSize,param);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(page);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 目录下载
     * @param ids
     */
    @Operation(summary = "目录下载")
    @PostMapping("/exportData/{ids}")
    public void exportData(HttpServletResponse response, @PathVariable("ids") String ids) {
        earthquakeDisasterInfoService.exportData(response, ids);
    }

    /**
     * 根据id查询
     * @param id 主键id
     * @return
     */
    @GetMapping("/findById")
    @Operation(summary = "根据id查询")
    public String findById(String id) {
        try {
            return earthquakeDisasterInfoService.findById(id);
        } catch (Exception e) {
            log.error("失败!", e);
            return null;
        }
    }
}
